package BookSystem;

//        名称
//        状态[未借/已借]
//        借出日期  2021-04-25 2021-04-27
//        借出次数

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Book {

    private String name;
    private String status;
    private Date loanDate;
    private int count;

    /**
     * 赋初始值
     */
    public Book() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

        this.name = null;
        this.status = "未借";
        try {
            this.loanDate = sdf.parse("0000年00月00日 00时00分00秒");
        } catch (ParseException e) {
//            e.printStackTrace();
        }
        count = 0;
    }

    public String getName() {
        return name;
    }

    public String getStatus() {
        return status;
    }

    public Date getLoanDate() {
        return loanDate;
    }

    public int getCount() {
        return count;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setLoanDate(Date loanDate) {
        this.loanDate = loanDate;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
        String loanDate = sdf.format(this.loanDate);
//        return "Book{" +
//                "书名 name='" + name + '\'' +
//                ", 状态 status='" + status + '\'' +
//                ", 借出时间 loanDate='" + loanDate + '\'' +
//                ", 借出次数 count=" + count +
//                '}';
        return "\t[" + name + "]\t[" + status + "]\t[" + loanDate + "]\t[" + count + "]\n";
    }
//    //为什么这个语句无效
//    @Override
//    public int compareTo(Book o) {
//        int t;
//        if (this.getCount() > o.getCount()) {
//            t = 1;
//        } else if (this.getCount() < o.getCount()) {
//            t = -1;
//        } else {
//            t = 0;
//        }
////        return this.getCount() - o.getCount();
//        return t;
//    }
}
